﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Model;

public partial class AjaxXml_UpdateVote : BasePage
{
    protected string Selects = "";
    protected int UpdateId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request["id"] != null)
        {
            UpdateId = StringHelper.isNumber_int(Request["id"]);
        }
        if (Request["Selects"] != null)
        {
            Selects = Request["Selects"];
        }
        Vote_Model VoteMd = Vote_Bll.CreateNew.GetModel(UpdateId);
        string cookvalue = Cookie.GetValue("VoteNum_" + StringHelper.Ip() + UpdateId);
        if (cookvalue == "CookieNonexistence" || cookvalue == "KeyNonexistence")
        {
            if (VoteMd.Id > 0)
            {
                #region MyRegion
                if (("," + Selects).IndexOf(",1,") >= 0)
                {
                    VoteMd.SumNum1 = VoteMd.SumNum1 + 1;
                }
                if (("," + Selects).IndexOf(",2,") >= 0)
                {
                    VoteMd.SumNum2 = VoteMd.SumNum2 + 1;
                }
                if (("," + Selects).IndexOf(",3,") >= 0)
                {
                    VoteMd.SumNum3 = VoteMd.SumNum3 + 1;
                }
                if (("," + Selects).IndexOf(",4,") >= 0)
                {
                    VoteMd.SumNum4 = VoteMd.SumNum4 + 1;
                }
                if (("," + Selects).IndexOf(",5,") >= 0)
                {
                    VoteMd.SumNum5 = VoteMd.SumNum5 + 1;
                }
                if (("," + Selects).IndexOf(",6,") >= 0)
                {
                    VoteMd.SumNum6 = VoteMd.SumNum6 + 1;
                }
                if (("," + Selects).IndexOf(",7,") >= 0)
                {
                    VoteMd.SumNum7 = VoteMd.SumNum7 + 1;
                }

                if (("," + Selects).IndexOf(",8,") >= 0)
                {
                    VoteMd.SumNum8 = VoteMd.SumNum8 + 1;
                }
                
                #endregion

                int Result = Vote_Bll.CreateNew.Update(VoteMd);
                if (Result > 0)
                {
                    Cookie.SetObj("VoteNum_" + StringHelper.Ip() + UpdateId, (60 * 60 * 24), "Ok");
                }
                Response.Write(1);
            }
            else
            {
                Response.Write(-1);
            }
        }
        else
        {
            Response.Write(-2);
        }

        //Response.Write(UpdateId + Selects);

    }
}
